package com.thf.controller.product;

import com.alibaba.fastjson.JSON;
import com.thf.model.ResultData;
import com.thf.service.ProductService;
import com.thf.util.Tool;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@Controller
public class ProductGoEditController {

    @Resource private ProductService poductService ;

    @RequestMapping("/back/product/goEdit")
    @ResponseBody
    protected String productGoEdit(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //     0。乱码处理
//        req.setCharacterEncoding("UTF-8");
//        resp.setCharacterEncoding("UTF-8");
        //        1.得到前端传递过来的数据
        String pid = req.getParameter("id");
        //        -返回值
        ResultData result = poductService.getProductById(Tool.stringToInt(pid));
        //       反馈给前端--返回值
        String resJson = JSON.toJSONString(result);
        //System.out.println(resJson);
//        resp.getWriter().println(resJson);
        return resJson ;
    }
}
